﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Oracle.ManagedDataAccess.Client;
using VswService_V7.DataBase.Tables.L2INTERFACE;
using VswService_V7.Utility;

namespace VswService_V7.DataBase.Tables
{
    public partial class TASK_INFO
    {
        /// <summary>
        /// 20 items of data per page
        /// </summary>
        public static int pageNum = 20;
        /// <summary>
        /// Task status
        /// </summary>
        public static readonly string createdNotBinded = "1";
        public static readonly string createdBinded = "2";
        public static readonly string started = "3";
        public static readonly string finished = "4";
        #region eventCode



        #endregion

        /// <summary>
        /// Page Task main menu interface initialization
        /// </summary>
        /// <param name="generalTaskTotalPages"></param>
        /// <param name="taskTaskTotalPages"></param>
        /// <param name="recipeTotalPages"></param>
        /// <param name="batchSRTotalPages"></param>
        /// <param name="stripSRTotalPages"></param>
        /// <returns></returns>
        public static DataTable[] InitPageTask(out string generalTaskTotalPages, out string taskTaskTotalPages, out string recipeTotalPages, out string batchSRTotalPages, out string stripSRTotalPages)
        {
            try
            {
                string sqlGeneraltask = string.Format("select * from (select ROWNUM rn,a.* from (select * from {0} where {1}<>'{2}' order by {3} desc,{4} desc) a) where rn>{5} and rn<={6}",
                   tableName, fd_status, finished, fd_status, fd_updateTime, 0, pageNum);
                string sqlGeneralTaskCount = string.Format("select count(*) from {0} where {1}<>'{2}'",
                  tableName, fd_status, finished);

                string sqlTasktask = string.Format("select * from (select ROWNUM rn,a.* from (select * from {0} order by {1} desc,{2} desc) a) where rn>{3} and rn<={4}",
                  tableName, fd_status, fd_updateTime, 0, pageNum);
                string sqlTaskTaskCount = string.Format("select count(*) from {0}",
                  tableName);

                string sqlrecipe = string.Format("select * from (select ROWNUM rn,a.* from (select * from {0} order by {1} desc) a) where rn>{2} and rn<={3}",
                            RECIPE_INFO.tableName, RECIPE_INFO.fd_createDate, 0, pageNum);
                string sqlrecipecount = string.Format("select count(*) from {0}",
                  RECIPE_INFO.tableName);

                string sqlbatchSampleRule = string.Format("select * from (select ROWNUM rn,a.* from (select * from {0} order by {1} desc) a) where rn>{2} and rn<={3}",
                  BATCH_SAMPLE_RULE.tableName, BATCH_SAMPLE_RULE.fd_updateTime, 0, pageNum);
                string sqlbatchSampleRulecount = string.Format("select count(*) from {0}",
                  BATCH_SAMPLE_RULE.tableName);

                string sqlstripSampleRule = string.Format("select * from (select ROWNUM rn,a.* from (select * from {0} order by {1} desc) a) where rn>{2} and rn<={3}",
                  STRIP_SAMPLE_RULE.tableName, STRIP_SAMPLE_RULE.fd_updateTime, 0, pageNum);
                string sqlstripSampleRulecount = string.Format("select count(*) from {0}",
                  STRIP_SAMPLE_RULE.tableName);

                string sqlProductionStandard = string.Format("select ROWNUM rn,a.* from (select * from {0} order by {1} desc) a",
                  PRODUCTION_STANDARD.tableName, PRODUCTION_STANDARD.fd_updateTime);

                DataTable generalTasktable = OracleHelper.Exct_QueryTable(sqlGeneraltask);
                DataTable taskTasktable = OracleHelper.Exct_QueryTable(sqlTasktask);
                DataTable recipetable = OracleHelper.Exct_QueryTable(sqlrecipe);
                DataTable batchTable = OracleHelper.Exct_QueryTable(sqlbatchSampleRule);
                DataTable stripTable = OracleHelper.Exct_QueryTable(sqlstripSampleRule);
                DataTable ProStandardTable = OracleHelper.Exct_QueryTable(sqlProductionStandard);

                if (stripTable != null)
                {
                    int generalTaskPages = Convert.ToInt32(GetTableCount(sqlGeneralTaskCount));
                    if (generalTaskPages % pageNum == 0)
                    {
                        generalTaskTotalPages = (generalTaskPages / pageNum).ToString();
                    }
                    else
                    {
                        generalTaskTotalPages = (generalTaskPages / pageNum + 1).ToString();
                    }

                    int taskTaskPages = Convert.ToInt32(GetTableCount(sqlTaskTaskCount));
                    if (taskTaskPages % pageNum == 0)
                    {
                        taskTaskTotalPages = (taskTaskPages / pageNum).ToString();
                    }
                    else
                    {
                        taskTaskTotalPages = (taskTaskPages / pageNum + 1).ToString();
                    }

                    int recipePages = Convert.ToInt32(GetTableCount(sqlrecipecount));
                    if (recipePages % pageNum == 0)
                    {
                        recipeTotalPages = (recipePages / pageNum).ToString();
                    }
                    else
                    {
                        recipeTotalPages = (recipePages / pageNum + 1).ToString();
                    }
                    int batchPages = Convert.ToInt32(GetTableCount(sqlbatchSampleRulecount));
                    if (batchPages % pageNum == 0)
                    {
                        batchSRTotalPages = (batchPages / pageNum).ToString();
                    }
                    else
                    {
                        batchSRTotalPages = (batchPages / pageNum + 1).ToString();
                    }
                    int stripPages = Convert.ToInt32(GetTableCount(sqlstripSampleRulecount));
                    if (stripPages % pageNum == 0)
                    {
                        stripSRTotalPages = (stripPages / pageNum).ToString();
                    }
                    else
                    {
                        stripSRTotalPages = (stripPages / pageNum + 1).ToString();
                    }
                    DataTable[] tables = new DataTable[] { generalTasktable, taskTasktable, recipetable, batchTable, stripTable, ProStandardTable };
                    LogHelper.WriteLog("InitPageTask Success");
                    return tables;
                }
                else
                {
                    generalTaskTotalPages = "";
                    taskTaskTotalPages = "";
                    recipeTotalPages = "";
                    batchSRTotalPages = "";
                    stripSRTotalPages = "";
                    return null;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("InitPageTask", ex);
                throw (ex);
            }
        }
        /// <summary>
        /// Paging query for unfinished tasks
        /// </summary>
        /// <param name="minRow"></param>
        /// <param name="maxRow"></param>
        /// <param name="recipeTotalPages"></param>
        /// <returns></returns>
        public static DataTable SelectGeneralTaskByIndex(int minRow, int maxRow, out string taskTotalPages)
        {
            try
            {
                string sqlGeneraltask = string.Format("select * from (select ROWNUM rn,a.* from (select * from {0} where {1}!='{2}' order by {3} desc,{4} desc) a) where rn>{5} and rn<={6}",
                   tableName, fd_status, finished, fd_status, fd_updateTime, minRow, maxRow);
                string sqlTaskcount = string.Format("select count(*) from  {0} where {1}!='{2}'",
                  tableName, fd_status, finished);
                DataTable taskTable = OracleHelper.Exct_QueryTable(sqlGeneraltask);
                if (taskTable != null)
                {
                    int taskPages = Convert.ToInt32(TASK_INFO.GetTableCount(sqlTaskcount));
                    if (taskPages % pageNum == 0)
                    {
                        taskTotalPages = (taskPages / pageNum).ToString();
                    }
                    else
                    {
                        taskTotalPages = (taskPages / pageNum + 1).ToString();
                    }
                    LogHelper.WriteLog("SelectGeneralTaskByIndex Success");
                    return taskTable;
                }
                else
                {
                    taskTotalPages = "";
                    return null; ;
                }

            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("SelectGeneralTaskByIndex", ex);
                throw ex;
            }
        }

        /// <summary>
        /// Get the total number of data
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static string GetTableCount(string sql)
        {
            try
            {
                var tempCount = OracleHelper.GetSingle(sql);
                if (tempCount != null)
                {
                    LogHelper.WriteLog("GetTableCount Success");
                    return tempCount.ToString();
                }
                else
                {
                    return "0";
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("GetTableCount", ex);
                throw (ex);
            }
        }
        /// <summary>
        /// insert Task
        /// </summary>
        /// <param name="taskTable"></param>
        /// <param name="userNo"></param>
        /// <returns></returns>
        public static DataTable Insert_TASK(DataTable taskTable, string userNo)
        {
            try
            {
                long eventNo = OracleHelper.GetNextEventNo();
                taskTable.Rows[0][fd_eventNo] = eventNo;
                string sqlTASK = string.Format("insert into {0} values({1},'{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}','{23}','{24}','{25}','{26}','{27}','{28}')",
                    tableName, eventNo, taskTable.Rows[0][fd_taskNo].ToString(), taskTable.Rows[0][fd_pipeQuantityBatch].ToString(), taskTable.Rows[0][fd_produceDestination].ToString(), taskTable.Rows[0][fd_priority].ToString(), taskTable.Rows[0][fd_batchSampleRule].ToString(), taskTable.Rows[0][fd_stripSampleRule].ToString(),
                    taskTable.Rows[0][fd_recipeNo].ToString(), taskTable.Rows[0][fd_productionStandard].ToString(), taskTable.Rows[0][fd_pipeDurabilityClass].ToString(), taskTable.Rows[0][fd_pipeSteelGrade].ToString(), taskTable.Rows[0][fd_pipeNominalMass].ToString(), taskTable.Rows[0][fd_pipeNominalLength].ToString(),
                    taskTable.Rows[0][fd_pipeMaxLength].ToString(), taskTable.Rows[0][fd_pipeMinLength].ToString(), taskTable.Rows[0][fd_pipeNominalOd].ToString(), taskTable.Rows[0][fd_pipeMaxOd].ToString(), taskTable.Rows[0][fd_pipeMinOd].ToString(), taskTable.Rows[0][fd_pipeNominalThickness].ToString(),
                    taskTable.Rows[0][fd_pipeMinThickness].ToString(), taskTable.Rows[0][fd_innerBeadIsremoving].ToString(), taskTable.Rows[0][fd_innerBeadHeight].ToString(), taskTable.Rows[0][fd_innerBeadDepth].ToString(), taskTable.Rows[0][fd_ovalityUpLimit].ToString(), taskTable.Rows[0][fd_bodyStraightness].ToString(),
                    taskTable.Rows[0][fd_endStraightness].ToString(), taskTable.Rows[0][fd_status].ToString(), taskTable.Rows[0][fd_updateTime].ToString());
                string sqlINTFTASK = string.Format("insert into {0} values({1},'{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}','{23}','{24}','{25}','{26}','{27}','{28}')",
                    L2INTF_TASK_INFO.tableName, eventNo, taskTable.Rows[0][fd_taskNo].ToString(), taskTable.Rows[0][fd_pipeQuantityBatch].ToString(), taskTable.Rows[0][fd_produceDestination].ToString(), taskTable.Rows[0][fd_priority].ToString(), taskTable.Rows[0][fd_batchSampleRule].ToString(), taskTable.Rows[0][fd_stripSampleRule].ToString(),
                    taskTable.Rows[0][fd_recipeNo].ToString(), taskTable.Rows[0][fd_productionStandard].ToString(), taskTable.Rows[0][fd_pipeDurabilityClass].ToString(), taskTable.Rows[0][fd_pipeSteelGrade].ToString(), taskTable.Rows[0][fd_pipeNominalMass].ToString(), taskTable.Rows[0][fd_pipeNominalLength].ToString(),
                    taskTable.Rows[0][fd_pipeMaxLength].ToString(), taskTable.Rows[0][fd_pipeMinLength].ToString(), taskTable.Rows[0][fd_pipeNominalOd].ToString(), taskTable.Rows[0][fd_pipeMaxOd].ToString(), taskTable.Rows[0][fd_pipeMinOd].ToString(), taskTable.Rows[0][fd_pipeNominalThickness].ToString(),
                    taskTable.Rows[0][fd_pipeMinThickness].ToString(), taskTable.Rows[0][fd_innerBeadIsremoving].ToString(), taskTable.Rows[0][fd_innerBeadHeight].ToString(), taskTable.Rows[0][fd_innerBeadDepth].ToString(), taskTable.Rows[0][fd_ovalityUpLimit].ToString(), taskTable.Rows[0][fd_bodyStraightness].ToString(),
                    taskTable.Rows[0][fd_endStraightness].ToString(), taskTable.Rows[0][fd_status].ToString(), taskTable.Rows[0][fd_updateTime].ToString());

                //string sqlINTFEVENT = string.Format("insert into {0} values({1},'{2}','{3}','{4}','{5}','{6}')",
                //    L2INTF_EVENT.tableName, eventNo, L2INTF_EVENT.insertNewTask, DateTime.Now.ToString(Formats.GetDateFormat()), "1", userNo, "");

                //need not inform L3, only record in L2, 2022/03/25
                string sqlINTFEVENT = string.Format("insert into {0} values({1},'{2}','{3}','{4}','{5}','{6}')",
                    L2INTF_EVENT.tableName, eventNo, L2INTF_EVENT.insertNewTask, DateTime.Now.ToString(Formats.GetDateFormat()), "2", userNo, "");

                List<string> sqlList = new List<string>();
                sqlList.Add(sqlTASK);
                sqlList.Add(sqlINTFTASK);
                sqlList.Add(sqlINTFEVENT);
                OracleHelper.ExecuteSqlTran(sqlList);
                LogHelper.WriteLog("Insert TASK Success!");
                return taskTable;
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("Insert_TASK", ex);
                throw ex;
            }
        }
        /// <summary>
        /// edit Task
        /// </summary>
        /// <param name="taskTable"></param>
        /// <param name="userNo"></param>
        /// <returns></returns>
        public static DataTable UpdateTaskByTaskNo(DataTable taskTable, string userNo)
        {
            try
            {
                long eventNo = OracleHelper.GetNextEventNo();
                taskTable.Rows[0][fd_eventNo] = eventNo;
                string sqlTASK = string.Format("UPDATE {0} SET {1}={2}, {3}='{4}', {5}='{6}',{7}='{8}',{9}='{10}',{11}='{12}',{13}='{14}',{15}='{16}',{17}='{18}',{19}='{20}'" +
                            ",{21}='{22}',{23}='{24}',{25}='{26}',{27}='{28}', {29}='{30}', {31}='{32}',{33}='{34}',{35}='{36}',{37}='{38}',{39}='{40}',{41}='{42}'" +
                            ",{43}='{44}',{45}='{46}',{47}='{48}',{49}='{50}', {51}='{52}', {53}='{54}' where {55}='{56}'",
                               tableName, fd_eventNo, eventNo, fd_pipeQuantityBatch, taskTable.Rows[0][fd_pipeQuantityBatch].ToString(), fd_produceDestination, taskTable.Rows[0][fd_produceDestination].ToString(), fd_priority, taskTable.Rows[0][fd_priority].ToString(),
                               fd_batchSampleRule, taskTable.Rows[0][fd_batchSampleRule].ToString(), fd_stripSampleRule, taskTable.Rows[0][fd_stripSampleRule].ToString(), fd_recipeNo, taskTable.Rows[0][fd_recipeNo].ToString(), fd_productionStandard, taskTable.Rows[0][fd_productionStandard].ToString(), fd_pipeDurabilityClass, taskTable.Rows[0][fd_pipeDurabilityClass].ToString(),
                               fd_pipeSteelGrade, taskTable.Rows[0][fd_pipeSteelGrade].ToString(), fd_pipeNominalMass, taskTable.Rows[0][fd_pipeNominalMass].ToString(), fd_pipeNominalLength, taskTable.Rows[0][fd_pipeNominalLength].ToString(), fd_pipeMaxLength, taskTable.Rows[0][fd_pipeMaxLength].ToString(), fd_pipeMinLength, taskTable.Rows[0][fd_pipeMinLength].ToString(),
                               fd_pipeNominalOd, taskTable.Rows[0][fd_pipeNominalOd].ToString(), fd_pipeMaxOd, taskTable.Rows[0][fd_pipeMaxOd].ToString(), fd_pipeMinOd, taskTable.Rows[0][fd_pipeMinOd].ToString(), fd_pipeNominalThickness, taskTable.Rows[0][fd_pipeNominalThickness].ToString(), fd_pipeMinThickness, taskTable.Rows[0][fd_pipeMinThickness].ToString(),
                               fd_innerBeadIsremoving, taskTable.Rows[0][fd_innerBeadIsremoving].ToString(), fd_innerBeadHeight, taskTable.Rows[0][fd_innerBeadHeight].ToString(), fd_innerBeadDepth, taskTable.Rows[0][fd_innerBeadDepth].ToString(), fd_ovalityUpLimit, taskTable.Rows[0][fd_ovalityUpLimit].ToString(), fd_bodyStraightness, taskTable.Rows[0][fd_bodyStraightness].ToString(),
                               fd_endStraightness, taskTable.Rows[0][fd_endStraightness].ToString(), fd_status, taskTable.Rows[0][fd_status].ToString(), fd_updateTime, taskTable.Rows[0][fd_updateTime].ToString(), fd_taskNo, taskTable.Rows[0][fd_taskNo].ToString());
                string sqlINTFTASK = string.Format("insert into {0} values({1},'{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}','{23}','{24}','{25}','{26}','{27}','{28}')",
                    L2INTF_TASK_INFO.tableName, eventNo, taskTable.Rows[0][fd_taskNo].ToString(), taskTable.Rows[0][fd_pipeQuantityBatch].ToString(), taskTable.Rows[0][fd_produceDestination].ToString(), taskTable.Rows[0][fd_priority].ToString(), taskTable.Rows[0][fd_batchSampleRule].ToString(), taskTable.Rows[0][fd_stripSampleRule].ToString(),
                    taskTable.Rows[0][fd_recipeNo].ToString(), taskTable.Rows[0][fd_productionStandard].ToString(), taskTable.Rows[0][fd_pipeDurabilityClass].ToString(), taskTable.Rows[0][fd_pipeSteelGrade].ToString(), taskTable.Rows[0][fd_pipeNominalMass].ToString(), taskTable.Rows[0][fd_pipeNominalLength].ToString(),
                    taskTable.Rows[0][fd_pipeMaxLength].ToString(), taskTable.Rows[0][fd_pipeMinLength].ToString(), taskTable.Rows[0][fd_pipeNominalOd].ToString(), taskTable.Rows[0][fd_pipeMaxOd].ToString(), taskTable.Rows[0][fd_pipeMinOd].ToString(), taskTable.Rows[0][fd_pipeNominalThickness].ToString(),
                    taskTable.Rows[0][fd_pipeMinThickness].ToString(), taskTable.Rows[0][fd_innerBeadIsremoving].ToString(), taskTable.Rows[0][fd_innerBeadHeight].ToString(), taskTable.Rows[0][fd_innerBeadDepth].ToString(), taskTable.Rows[0][fd_ovalityUpLimit].ToString(), taskTable.Rows[0][fd_bodyStraightness].ToString(),
                    taskTable.Rows[0][fd_endStraightness].ToString(), taskTable.Rows[0][fd_status].ToString(), taskTable.Rows[0][fd_updateTime].ToString());
                string sqlINTFEVENT = string.Format("insert into {0} values({1},'{2}','{3}','{4}','{5}','{6}')",
                    L2INTF_EVENT.tableName, eventNo, L2INTF_EVENT.editTask, DateTime.Now.ToString(Formats.GetDateFormat()), "1", userNo, "");
                List<string> sqlList = new List<string>();
                sqlList.Add(sqlTASK);
                sqlList.Add(sqlINTFTASK);
                sqlList.Add(sqlINTFEVENT);

                OracleHelper.ExecuteSqlTran(sqlList);
                LogHelper.WriteLog("UpdateTaskByTaskNo Success!");
                return taskTable;
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("UpdateTaskByTaskNo", ex);
                throw ex;
            }
        }
        /// <summary>
        /// delete Task
        /// </summary>
        /// <param name="taskNo"></param>
        /// <param name="userNo"></param>
        /// <returns></returns>
        public static DataTable DeleteUnloadingTask(string taskNo, string userNo, int minRow, int maxRow, out string taskTotalPages)
        {
            try
            {
                long eventNo = OracleHelper.GetNextEventNo();
                string sql = string.Format("select * from {0} where {1}='{2}'", tableName, fd_taskNo, taskNo);
                DataTable taskTable = OracleHelper.Exct_QueryTable(sql);
                if (taskTable != null && taskTable.Rows.Count > 0)
                {
                    string deleteTaskSql = string.Format("delete from {0} where {1}='{2}'",
                     tableName, fd_taskNo, taskNo);
                    string deleteStripSql = string.Format("delete from {0} where {1}='{2}'",
                      STRIP_INFO.tableName, STRIP_INFO.fd_taskNo, taskNo);
                    string sqlINTFTASKDELETE = string.Format("insert into {0} values({1},'{2}','{3}')",
                        L2INTF_TASK_DELETE.tableName, eventNo, taskTable.Rows[0][fd_taskNo].ToString(), DateTime.Now.ToString(Formats.GetDateFormat())
                        );

                    //string sqlINTFEVENT = string.Format("insert into {0} values({1},'{2}','{3}','{4}','{5}','{6}')",
                    //    L2INTF_EVENT.tableName, eventNo, L2INTF_EVENT.deleteTask, DateTime.Now.ToString(Formats.GetDateFormat()), "1", userNo, "");
                    // need not inform L3 ,only record in L2, 2022-03-25
                    string sqlINTFEVENT = string.Format("insert into {0} values({1},'{2}','{3}','{4}','{5}','{6}')",
                        L2INTF_EVENT.tableName, eventNo, L2INTF_EVENT.deleteTask, DateTime.Now.ToString(Formats.GetDateFormat()), "2", userNo, "");
                    List<string> sqlList = new List<string>();
                    sqlList.Add(deleteTaskSql);
                    sqlList.Add(deleteStripSql);
                    sqlList.Add(sqlINTFTASKDELETE);
                    sqlList.Add(sqlINTFEVENT);
                    OracleHelper.ExecuteSqlTran(sqlList);
                    LogHelper.WriteLog("DeleteUnloadingTask Success!");
                    return SelectTaskTaskByIndex(minRow, maxRow, out taskTotalPages);
                }
                else
                {
                    taskTotalPages = "";

                    return null;
                }
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("DeleteUnloadingTask", ex);
                throw ex;
            }
        }
        /// <summary>
        /// fuzzy query task information 
        /// </summary>
        /// <param name="task_No">部分taskNo</param>
        /// <returns></returns>
        public static DataTable SelectTaskByParameters(string sqltask, int minRow, int maxRow, out string totalPages)
        {
            try
            {
                string sql = sqltask + string.Format(" where rn>{0} and rn<={1}", minRow, maxRow);
                string sqlCount = string.Format("select count(*) from ({0})",
                   sqltask);
                DataTable Table = OracleHelper.Exct_QueryTable(sql);
                if (Table != null)
                {
                    int Pages = Convert.ToInt32(GetTableCount(sqlCount));
                    if (Pages % pageNum == 0)
                    {
                        totalPages = (Pages / pageNum).ToString();
                    }
                    else
                    {
                        totalPages = (Pages / pageNum + 1).ToString();
                    }
                    LogHelper.WriteLog("SelectTaskByParameters Success");
                    return Table;
                }
                else
                {
                    totalPages = "";
                    return null;
                }

            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("SelectTaskByParameters", ex);
                throw ex;
            }
        }

        /// <summary>
        /// pagination query all task information
        /// </summary>
        /// <param name="minRow"></param>
        /// <param name="maxRow"></param>
        /// <param name="recipeTotalPages"></param>
        /// <returns></returns>
        public static DataTable SelectTaskTaskByIndex(int minRow, int maxRow, out string taskTotalPages)
        {
            try
            {
                string sqlTask = string.Format("select * from (select ROWNUM rn,a.* from (select * from {0} a order by {1} desc,{2} desc) a) where rn>{3} and rn<={4}",
                  tableName, fd_status, fd_updateTime, minRow, maxRow);
                string sqlTaskCount = string.Format("select count(*) from {0}",
                  tableName);
                DataTable taskTable = OracleHelper.Exct_QueryTable(sqlTask);
                if (taskTable != null)
                {
                    int taskPages = Convert.ToInt32(GetTableCount(sqlTaskCount));
                    if (taskPages % pageNum == 0)
                    {
                        taskTotalPages = (taskPages / pageNum).ToString();
                    }
                    else
                    {
                        taskTotalPages = (taskPages / pageNum + 1).ToString();
                    }
                    LogHelper.WriteLog("SelectTaskTaskByIndex Success");
                    return taskTable;
                }
                else
                {
                    taskTotalPages = "";
                    return null; ;
                }

            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("SelectTaskTaskByIndex", ex);
                throw ex;
            }
        }
        /// <summary>
        /// pagination query task information
        /// </summary>
        /// <param name="minRow"></param>
        /// <param name="maxRow"></param>
        /// <param name="taskTotalPages"></param>
        /// <returns></returns>
        public static DataTable QueryTaskByTaskNoByIndex(string sql, int minRow, int maxRow, out string taskTotalPages)
        {
            try
            {
                string sqlTask = string.Format("select * from (select a.*,ROWNUM rn from {0} a {1} order by {2} desc,{3} desc) where rn>{4} and rn<={5}",
                  tableName, sql, fd_updateTime, fd_taskNo, minRow, maxRow);
                string sqlTaskCount = string.Format("select count(*) from (select * from {0} {1})",
                   tableName, sql);
                DataTable taskTable = OracleHelper.Exct_QueryTable(sqlTask);
                if (taskTable != null)
                {
                    int taskPages = Convert.ToInt32(GetTableCount(sqlTaskCount));
                    if (taskPages % pageNum == 0)
                    {
                        taskTotalPages = (taskPages / pageNum).ToString();
                    }
                    else
                    {
                        taskTotalPages = (taskPages / pageNum + 1).ToString();
                    }
                    LogHelper.WriteLog("QueryTaskByTaskNoByIndex Success");
                    return taskTable;
                }
                else
                {
                    taskTotalPages = "";
                    return null; ;
                }

            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("QueryTaskByTaskNoByIndex", ex);
                throw ex;
            }
        }
    }
}
